package com.zx.callback.common.properties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * 支付宝配置
 * Created by yanst on 2017/8/10.
 */
@Component
public class AlipayConfig {
    private static Logger logger = LoggerFactory.getLogger(AlipayConfig.class);

    // 应用ID,您的APPID，收款账号既是您的APPID对应支付宝账号
    public static String app_id;

    // 支付宝公钥,查看地址：https://openhome.alipay.com/platform/keyManage.htm 对应APPID下的支付宝公钥。
    public static String alipay_public_key;

    // 签名方式
    public static String sign_type;

    // 字符编码格式
    public static String charset;

    // 支付宝网关
    public static String gatewayUrl;

    // 支付宝服务费率
    public static String serviceRate;

    @Value("${alipay.app.id}")
    public void setApp_id(String app_id) {
        AlipayConfig.app_id = app_id;
        if (logger.isDebugEnabled()) {
            logger.debug("支付宝配置初始化数据：应用ID={}", AlipayConfig.app_id);
        }
    }

    @Value("${alipay.alipay.public.key}")
    public void setAlipay_public_key(String alipay_public_key) {
        AlipayConfig.alipay_public_key = alipay_public_key;
        if (logger.isDebugEnabled()) {
            logger.debug("支付宝配置初始化数据：支付宝公钥={}", AlipayConfig.alipay_public_key);
        }
    }

    @Value("${alipay.sign.type}")
    public void setSign_type(String sign_type) {
        AlipayConfig.sign_type = sign_type;
        if (logger.isDebugEnabled()) {
            logger.debug("支付宝配置初始化数据：签名方式={}", AlipayConfig.sign_type);
        }
    }

    @Value("${alipay.charset}")
    public void setCharset(String charset) {
        AlipayConfig.charset = charset;
        if (logger.isDebugEnabled()) {
            logger.debug("支付宝配置初始化数据：字符编码格式={}", AlipayConfig.charset);
        }
    }

    @Value("${alipay.gateway.url}")
    public void setGatewayUrl(String gatewayUrl) {
        AlipayConfig.gatewayUrl = gatewayUrl;
        if (logger.isDebugEnabled()) {
            logger.debug("支付宝配置初始化数据：支付宝网关={}", AlipayConfig.gatewayUrl);
        }
    }

    @Value("${alipay.service.rate}")
    public void setServiceRate(String serviceRate) {
        AlipayConfig.serviceRate = serviceRate;
        if (logger.isDebugEnabled()) {
            logger.debug("支付宝配置初始化数据：支付宝服务费率={}", AlipayConfig.serviceRate);
        }
    }
}
